<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>弹簧</title>
</head>
<body>
   <canvas id="canvas" width="500" height="500" style="background-color: #000;">
	your browser not support canvas!
</canvas>

<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/ball.js"></script>
   <script>
       window.onload = function () {
      var canvas = document.getElementById('canvas'),
          context = canvas.getContext('2d'),
          ball = new Ball(),
          spring = 0.03,
          targetX = canvas.width / 2,
          vx = 0;

      ball.y = canvas.height / 2;

      (function drawFrame () {
        window.requestAnimationFrame(drawFrame, canvas);
        context.clearRect(0, 0, canvas.width, canvas.height);

        var dx = targetX - ball.x,
            ax = dx * spring;

        vx += ax;
        ball.x += vx;
        ball.draw(context);
      }());
    };
    </script>
    
</body>
</html>